package blockr;

import blockr.function.*;
import blockr.model.RandomNumOBJ;

import java.io.IOException;

/**
 * @author spencercjh
 */
public class Encrypt {

    public static byte[][][] encrypt(String inputfile, RandomNumOBJ firstBlockKey) {
        int arraySize = firstBlockKey.getR1().length;
        try {
            MappedBiggerFileReader.Read_File(inputfile, arraySize);
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("i/o失败");
        }
        byte[][] allPiece = MappedBiggerFileReader.getAll_Piece();
        byte[][][] allBlock = MappedBiggerFileReader.getAll_Block();

        // 分片
        Fill_Final_Piece.Fill(allPiece, allBlock, arraySize);
        try {
            allBlock = Do_Encrypt.DoEncrypt(allPiece, allBlock, GetCipherCode.CipherCode(arraySize), firstBlockKey, arraySize);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("DoEncrypt失败");
        }

        return allBlock;
    }

}
